#include <stdio.h>

int convertTo10(int n[], int len, int y){
	int sum = 0;
	int u = 1;  
	for(int a=len-1; a>=0; a--){
		sum += n[a]*u;
		u *= y;
	} 
	return sum;
}

int main(){	
	int m,k;
	scanf("%d %d",&m,&k);
	int x[m];
	for (int t=0; t<m; t++)
		x[t] = k-1;
	printf("%d",convertTo10(x,m,k));
} 


